const express = require('express')
const app = express()
const jwt = require('jsonwebtoken')
//token验证
app.post('/api/token', (req, res) => {
  let token = req.headers.authorization
  new Promise((resolve,reject)=>{
    resolve(jwt.verify(token, 'jwt'))
  }).then(()=>{
    return res.send({
      code:200
    })
  }).catch(err=>{
    return res.send({
        code:400,
        msg:err.message
    })
  })
})
app.use(express.urlencoded({
  extended: false
}))
//首页
app.use(require('./router/home'))
//分类
app.use(require('./router/list'))
//详情页
app.use(require('./router/detail'))
//登录注册
app.use(require('./router/login'))
//购物车
app.use(require('./router/cart'))
//地址
app.use(require('./router/path'))
//支付,订单
app.use(require('./router/order'))
app.listen(3000, () => {
  console.log('3000端口启动');
})
